package com.my.springbootemail.service.impl;

import com.my.springbootemail.bean.Mail;
import com.my.springbootemail.service.MailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Author marshal
 * @Date 2021-06-12 12:47 PM
 */
@Service
public class MailServiceImpl implements MailService {

    @Value("${spring.mail.username}")
    private String from;

    @Autowired
    private JavaMailSender mailSender;


    @Override
    public void sendSimpleMail(Mail mail) {
        var message = new SimpleMailMessage();
        BeanUtils.copyProperties(mail, message);
        message.setFrom(from);
        mailSender.send(message);
    }
}
